<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :loading="loading"
        :columns="columns"
        :pagination="false"
        :dataSource="dataSource">
      </a-table>
    </j-form-container>
  </a-spin>
</template>

<script>
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'ErpOmcPaymentViewsForm',
  props: {
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      confirmLoading: false,
      loading: false,
      dictOptions: {},
      dataSource: [],
      url: {
        queryListByMainId: '/api/erp/progress/erpProgressPaymentNodeDt/queryListByMainId'
      },
      columns: [
          {
            title: '收款单编号',
            align: 'center',
            dataIndex: 'billNo'
          },
          {
            title: '汇款单位',
            align: 'center',
            dataIndex: 'erpOmcCustomerManager_dictText'
          },
          {
            title: '汇款日期',
            align: 'center',
            dataIndex: 'remittanceDate'
          },
          {
            title: '收款单位',
            align: 'center',
            dataIndex: 'payeeUnit_dictText'
          },
          {
            title: '收款账户',
            align: 'center',
            dataIndex: 'payeeAccountNo',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['payeeAccountNo'], text + '')
              }
            }
          },
          {
            title: '收款金额（元）',
            align: 'center',
            dataIndex: 'remittanceAmount'
          },
          {
            title: '扣款金额（元）',
            align: 'center',
            dataIndex: 'deductMoney'
          }
        ]
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    this.initDictConfig()
  },
  methods: {
    initDictConfig() {
        // todo  收款单回显
        initDictOptions('sys_depart_bank_info,bank_card_no,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'payeeAccountNo', res.result)
          }
        })
      },
    add() {
      // this.edit(this.modelDefault);
    },
    edit(record, flag) {
      this.visible = true;
      this.changeDataSource(record.id)
    },
    changeDataSource(val) {
      this.dataSource = []
      this.loading = true
      let url = this.url.queryListByMainId;
      let param = {
        id: val
      }
      getAction(url, param).then((res) => {
        if (res.success) {
          if (!Array.isArray(res.result)) {
            this.dataSource.push(res.result);
          } else {
            for (let i = 0; i < res.result.length; i++) {
              this.dataSource.push(res.result[i]);
            }
          }
        } else {
          this.dataSource = []
        }
      }).finally(() => {
            this.loading = false;
          })
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          this.$set(this.model, 'paymentId', this.model.id)
          this.$emit('ok', this.model);
        }
      })
    }
  }
}
</script>
